package com.love.marriage.menuInfo.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.love.marriage.common.interfaces.avoid.AvoidRepeatableCommit;
import com.love.marriage.common.validator.Insert;
import com.love.marriage.common.validator.Update;
import com.love.marriage.common.vo.Result;
import com.love.marriage.common.vo.ResultBoolean;
import com.love.marriage.menuInfo.service.MenuInfoService;
import com.love.marriage.menuInfo.vo.MenuInfoVo;
import com.love.marriage.menuInfo.vo.ResultMenuInfoListVo;
import com.love.marriage.menuInfo.vo.ResultMenuInfoPageVo;
import com.love.marriage.menuInfo.vo.ResultMenuInfoVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * description:  菜单管理表restApi
 * author:       alex
 * createDate:   2023-12-19 17:34:23
 * version:      1.0.0
 */
@ApiSort(105)
@Tag(name = "菜单管理表相关接口", description = "菜单管理表相关接口")
@RestController
@RequiredArgsConstructor
@RequestMapping("/menu-info")
public class MenuInfoController {

    private final MenuInfoService menuInfoService;

    @ApiOperationSupport(order = 10, author = "alex")
    @Operation(summary = "获取菜单管理表分页", description = "获取菜单管理表分页",
            requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
                    description = "查询条件",
                    required = false,
                    content = @Content(schema = @Schema(implementation = MenuInfoVo.class))
            ))
    @PostMapping(value = "/page")
    @Parameters({
            @Parameter(description = "页码", name = "pageNum", schema = @Schema(implementation = Integer.class, type = "Integer", example = "1")),
            @Parameter(description = "每页大小", name = "pageSize", schema = @Schema(implementation = Integer.class, type = "Integer", example = "10"))}
    )
    @Tag(name = "test")
    @ApiResponse(responseCode = "200", description = "菜单管理表分页",
            content = @Content(mediaType = "application/json",
                    schema = @Schema(implementation = ResultMenuInfoPageVo.class
                    )))
    public Result<Page<MenuInfoVo>> getPage(@RequestParam(value = "pageNum", required = false) Long pageNum,
                                            @RequestParam(value = "pageSize", required = false) Long pageSize,
                                            @RequestBody(required = false) MenuInfoVo menuInfoVo) {
        return Result.success(menuInfoService.getPage(pageNum, pageSize, menuInfoVo));
    }

    @ApiOperationSupport(order = 15, author = "alex")
    @Operation(summary = "获取菜单管理列表", description = "获取菜单管理列表",
            requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
                    description = "查询条件",
                    required = false,
                    content = @Content(schema = @Schema(implementation = MenuInfoVo.class))
            ))
    @PostMapping(value = "/list")
    @ApiResponse(responseCode = "200", description = "菜单管理表分页",
            content = @Content(schema = @Schema(implementation = ResultMenuInfoListVo.class)))
    public Result<List<MenuInfoVo>> getList(@RequestBody(required = false) MenuInfoVo menuInfoVo) {
        return Result.success(menuInfoService.getList(menuInfoVo));
    }

    @ApiOperationSupport(order = 20, author = "alex")
    @Operation(summary = "获取菜单管理表详情", description = "获取菜单管理表详情")
    @GetMapping
    @Parameters({
            @Parameter(description = "id", name = "id", schema = @Schema(implementation = String.class, type = "String", example = "123"))}
    )
    @ApiResponse(responseCode = "200", description = "获取菜单管理表详情",
            content = @Content(schema = @Schema(implementation = ResultMenuInfoVo.class)))
    public Result<MenuInfoVo> query(@RequestParam(value = "id") String id) {
        return Result.success(menuInfoService.queryMenuInfo(id));
    }

    @AvoidRepeatableCommit
    @ApiOperationSupport(order = 30, author = "alex")
    @Operation(summary = "新增菜单管理表", description = "新增菜单管理表",
            requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
                    description = "查询条件",
                    required = false,
                    content = @Content(schema = @Schema(implementation = MenuInfoVo.class))
            ))
    @PostMapping
    @ApiResponse(responseCode = "200", description = "新增菜单管理表成功",
            content = @Content(schema = @Schema(implementation = ResultMenuInfoVo.class)))
    public Result<MenuInfoVo> add(@Validated({Insert.class}) @RequestBody MenuInfoVo menuInfoVo) {
        return Result.success(menuInfoService.addMenuInfo(menuInfoVo));
    }

    @ApiOperationSupport(order = 40, author = "alex")
    @Operation(summary = "修改菜单管理表", description = "修改菜单管理表",
            requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
                    description = "查询条件",
                    content = @Content(schema = @Schema(implementation = MenuInfoVo.class))
            ))
    @PutMapping
    @ApiResponse(responseCode = "200", description = "修改菜单管理表成功",
            content = @Content(schema = @Schema(implementation = ResultMenuInfoVo.class)))
    public Result<MenuInfoVo> update(@Validated({Update.class}) @RequestBody MenuInfoVo menuInfoVo) {
        return Result.success(menuInfoService.updateMenuInfo(menuInfoVo));
    }

    @ApiOperationSupport(order = 50, author = "alex")
    @Operation(summary = "刪除菜单管理表", description = "刪除菜单管理表")
    @DeleteMapping
    @ApiResponse(responseCode = "200", description = "刪除菜单管理表成功",
            content = @Content(schema = @Schema(implementation = ResultBoolean.class)))
    public Result<Boolean> delete(@RequestParam("ids") String ids) {
        return Result.success(menuInfoService.deleteMenuInfo(ids));
    }
}
